package classign.election.kingvar.come.electionclasssign.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

import classign.election.kingvar.come.electionclasssign.R;

/**
 * Created by Administrator on 2016/12/23 0023.
 */

public class Adapter extends PagerAdapter {
	private ArrayList<View> views;
	private int[] imgs = {R.drawable.test1, R.drawable.test2, R.drawable.test3,R.drawable.test4, R.drawable.test5, R.drawable.test6
			,R.drawable.test7, R.drawable.test8, R.drawable.test8};
	Context context;
	public Adapter(Context context) {
		this.context =context;
		/*views = new ArrayList<>();
		views.add(View.inflate(context, R.layout.item_img, null));
		views.get(0).findViewById(R.id.btn_buy).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
//				Toast.makeText(context, "buy", Toast.LENGTH_SHORT).show();
			}
		});
		views.add(View.inflate(context, R.layout.item_img, null));
android:transitionName="pic"
		views.add(View.inflate(context, R.layout.item_img, null));*/
	}



	@Override
	public int getCount() {
		return imgs.length;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		ViewHolder viewHolder = null;
		View view =null;
		if (view ==null){
			view = LayoutInflater.from(context).inflate(R.layout.item_class_album, null);
		}
		if (viewHolder == null) {
			viewHolder = new ViewHolder();
		}
		viewHolder.welfareImage = (ImageView) view.findViewById(R.id.welfare_image);
		viewHolder.welfareImage.setImageResource(imgs[position]);

//		Glide.with(activity).load(BaseProtocol.IMG_BASE + mHonorList.get(position).getImg()).into(viewHolder.welfareImage);
		container.addView(view);
		return view;
/*		views.get(position).findViewById(R.id.imageView).setBackgroundResource(imgs[position]);
		container.addView(views.get(position));

		return views.get(position);*/
	}
	class ViewHolder {
		ImageView welfareImage;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
//		container.removeView(views.get(position));
		container.removeView((View) object);
	}
}
